from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-12 14:12:24.456686
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 12, Sep, 2021
Time: 14:12:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1258
Nobs: 412.000 HQIC: -46.6568
Log likelihood: 4511.45 FPE: 3.85800e-21
AIC: -47.0042 Det(Omega_mle): 3.10903e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435256 0.092909 4.685 0.000
L1.Burgenland 0.105051 0.048156 2.181 0.029
L1.Kärnten -0.113831 0.023966 -4.750 0.000
L1.Niederösterreich 0.172595 0.103329 1.670 0.095
L1.Oberösterreich 0.124502 0.101015 1.233 0.218
L1.Salzburg 0.283588 0.050467 5.619 0.000
L1.Steiermark 0.020428 0.066896 0.305 0.760
L1.Tirol 0.108534 0.052833 2.054 0.040
L1.Vorarlberg -0.111497 0.047540 -2.345 0.019
L1.Wien -0.017274 0.092050 -0.188 0.851
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014387 0.215297 0.067 0.947
L1.Burgenland -0.046384 0.111591 -0.416 0.678
L1.Kärnten 0.037630 0.055537 0.678 0.498
L1.Niederösterreich -0.212932 0.239444 -0.889 0.374
L1.Oberösterreich 0.487833 0.234081 2.084 0.037
L1.Salzburg 0.305289 0.116946 2.611 0.009
L1.Steiermark 0.113078 0.155018 0.729 0.466
L1.Tirol 0.314189 0.122429 2.566 0.010
L1.Vorarlberg 0.002731 0.110165 0.025 0.980
L1.Wien -0.004206 0.213308 -0.020 0.984
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248355 0.047436 5.236 0.000
L1.Burgenland 0.089808 0.024587 3.653 0.000
L1.Kärnten -0.001674 0.012236 -0.137 0.891
L1.Niederösterreich 0.208851 0.052756 3.959 0.000
L1.Oberösterreich 0.167739 0.051574 3.252 0.001
L1.Salzburg 0.033610 0.025766 1.304 0.192
L1.Steiermark 0.019357 0.034155 0.567 0.571
L1.Tirol 0.066911 0.026974 2.481 0.013
L1.Vorarlberg 0.059842 0.024272 2.465 0.014
L1.Wien 0.108988 0.046997 2.319 0.020
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180822 0.046340 3.902 0.000
L1.Burgenland 0.048727 0.024019 2.029 0.042
L1.Kärnten -0.006617 0.011954 -0.554 0.580
L1.Niederösterreich 0.138102 0.051537 2.680 0.007
L1.Oberösterreich 0.317698 0.050383 6.306 0.000
L1.Salzburg 0.100483 0.025171 3.992 0.000
L1.Steiermark 0.132191 0.033366 3.962 0.000
L1.Tirol 0.075266 0.026351 2.856 0.004
L1.Vorarlberg 0.057151 0.023712 2.410 0.016
L1.Wien -0.044071 0.045912 -0.960 0.337
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210585 0.092126 2.286 0.022
L1.Burgenland -0.054446 0.047750 -1.140 0.254
L1.Kärnten -0.035116 0.023764 -1.478 0.139
L1.Niederösterreich 0.110911 0.102458 1.082 0.279
L1.Oberösterreich 0.172905 0.100163 1.726 0.084
L1.Salzburg 0.255370 0.050041 5.103 0.000
L1.Steiermark 0.079411 0.066332 1.197 0.231
L1.Tirol 0.124859 0.052387 2.383 0.017
L1.Vorarlberg 0.114334 0.047140 2.425 0.015
L1.Wien 0.025458 0.091275 0.279 0.780
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028699 0.071384 0.402 0.688
L1.Burgenland 0.024978 0.036999 0.675 0.500
L1.Kärnten 0.052256 0.018414 2.838 0.005
L1.Niederösterreich 0.210297 0.079389 2.649 0.008
L1.Oberösterreich 0.336010 0.077611 4.329 0.000
L1.Salzburg 0.044682 0.038774 1.152 0.249
L1.Steiermark -0.005931 0.051398 -0.115 0.908
L1.Tirol 0.113482 0.040592 2.796 0.005
L1.Vorarlberg 0.065968 0.036526 1.806 0.071
L1.Wien 0.130334 0.070724 1.843 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186086 0.087389 2.129 0.033
L1.Burgenland 0.019131 0.045295 0.422 0.673
L1.Kärnten -0.057288 0.022542 -2.541 0.011
L1.Niederösterreich -0.111698 0.097190 -1.149 0.250
L1.Oberösterreich 0.189687 0.095013 1.996 0.046
L1.Salzburg 0.030376 0.047468 0.640 0.522
L1.Steiermark 0.299604 0.062922 4.762 0.000
L1.Tirol 0.485926 0.049694 9.778 0.000
L1.Vorarlberg 0.069146 0.044716 1.546 0.122
L1.Wien -0.108050 0.086581 -1.248 0.212
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160321 0.095021 1.687 0.092
L1.Burgenland -0.005897 0.049251 -0.120 0.905
L1.Kärnten 0.061663 0.024511 2.516 0.012
L1.Niederösterreich 0.181878 0.105679 1.721 0.085
L1.Oberösterreich -0.127001 0.103312 -1.229 0.219
L1.Salzburg 0.235915 0.051614 4.571 0.000
L1.Steiermark 0.159500 0.068417 2.331 0.020
L1.Tirol 0.052085 0.054034 0.964 0.335
L1.Vorarlberg 0.125577 0.048621 2.583 0.010
L1.Wien 0.158540 0.094143 1.684 0.092
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.484729 0.051523 9.408 0.000
L1.Burgenland -0.010836 0.026705 -0.406 0.685
L1.Kärnten -0.009789 0.013291 -0.737 0.461
L1.Niederösterreich 0.209945 0.057302 3.664 0.000
L1.Oberösterreich 0.262362 0.056018 4.684 0.000
L1.Salzburg 0.022821 0.027986 0.815 0.415
L1.Steiermark -0.026279 0.037098 -0.708 0.479
L1.Tirol 0.066363 0.029299 2.265 0.024
L1.Vorarlberg 0.056513 0.026364 2.144 0.032
L1.Wien -0.052587 0.051047 -1.030 0.303
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020510 0.078222 0.138446 0.134669 0.040649 0.072983 -0.002288 0.173183
Kärnten 0.020510 1.000000 -0.045543 0.126608 0.046301 0.070333 0.455046 -0.094400 0.091701
Niederösterreich 0.078222 -0.045543 1.000000 0.284470 0.081020 0.266902 0.021542 0.139482 0.261621
Oberösterreich 0.138446 0.126608 0.284470 1.000000 0.180547 0.285246 0.156357 0.099804 0.138101
Salzburg 0.134669 0.046301 0.081020 0.180547 1.000000 0.127818 0.055566 0.105144 0.049788
Steiermark 0.040649 0.070333 0.266902 0.285246 0.127818 1.000000 0.131208 0.088902 -0.024174
Tirol 0.072983 0.455046 0.021542 0.156357 0.055566 0.131208 1.000000 0.038718 0.116954
Vorarlberg -0.002288 -0.094400 0.139482 0.099804 0.105144 0.088902 0.038718 1.000000 -0.047519
Wien 0.173183 0.091701 0.261621 0.138101 0.049788 -0.024174 0.116954 -0.047519 1.000000